import {Service, action} from "adajs";
import Page from "./../lib/page";

class TabService extends Service {
	setTabs(tabs) {
		let setted = false;
		tabs.forEach(tab => {
			let a = Page.get();
			if (Page.hashCode(tab.name) === a) {
				tab.active = true;
				tab.loaded = true;
				setted = true;
			} else {
				tab.active = false;
				tab.loaded = false;
			}
		});
		if (!setted) {
			if (tabs[0]) {
				tabs[0].active = true;
				tabs[0].loaded = false;
			}
		}
	}

	@action("setTab")
	setTab(current, name) {
		Page.set(name);
	}
}

export default TabService;